renderbackground: Only query number of layers once
authorTimm Bäder <mail@baedert.org>
Sun, 21 Jun 2020 06:44:12 +0000 (08:44 +0200)
committerTimm Bäder <mail@baedert.org>
Sat, 27 Jun 2020 08:51:06 +0000 (10:51 +0200)
We did it once in snapshot_background and then again in snapshot_color.

gtk/gtkrenderbackground.c

index 11c9c109c668b03d29f34c9c0c9b3854fc965c12..7630ab704b41af3913fa877e89728d6bdeb025c9 100644 (file)
@@ -47,14 +47,12 @@ static void
 gtk_theming_background_snapshot_color (GtkCssBoxes       *boxes,
                                        GtkSnapshot       *snapshot,
                                        const GdkRGBA     *bg_color,
-                                       const GtkCssValue *background_image)
+                                       guint              n_bg_values)
 {
   const GskRoundedRect *box;
-  gint n_values;
   GtkCssArea clip;
-    
-  n_values = _gtk_css_array_value_get_n_values (background_image);
-  clip = _gtk_css_area_value_get (_gtk_css_array_value_get_nth (boxes->style->background->background_clip, n_values - 1)); 
+
+  clip = _gtk_css_area_value_get (_gtk_css_array_value_get_nth (boxes->style->background->background_clip, n_bg_values - 1));
   box = gtk_css_boxes_get_box (boxes, clip);
 
   if (gsk_rounded_rect_is_rectilinear (box))
@@ -264,7 +262,8 @@ gtk_css_style_snapshot_background (GtkCssBoxes *boxes,
   gboolean has_bg_color;
   gboolean has_bg_image;
   gboolean has_shadow;
-  gint idx;
+  int idx;
+  guint number_of_layers;
 
   if (background->base.type == GTK_CSS_BACKGROUND_INITIAL_VALUES)
     return;
@@ -288,10 +287,11 @@ gtk_css_style_snapshot_background (GtkCssBoxes *boxes,
                                           snapshot,
                                           gtk_css_boxes_get_border_box (boxes));
 
+  number_of_layers = _gtk_css_array_value_get_n_values (background_image);
+
   if (has_bg_image)
     {
       GtkCssValue *blend_modes = background->background_blend_mode;
-      const int number_of_layers = _gtk_css_array_value_get_n_values (background_image);
       GskBlendMode *blend_mode_values = g_alloca (sizeof (GskBlendMode) * number_of_layers);
 
       for (idx = number_of_layers - 1; idx >= 0; idx--)
@@ -303,7 +303,7 @@ gtk_css_style_snapshot_background (GtkCssBoxes *boxes,
         }
 
       if (has_bg_color)
-        gtk_theming_background_snapshot_color (boxes, snapshot, bg_color, background_image);
+        gtk_theming_background_snapshot_color (boxes, snapshot, bg_color, number_of_layers);
 
       for (idx = number_of_layers - 1; idx >= 0; idx--)
         {
@@ -321,7 +321,7 @@ gtk_css_style_snapshot_background (GtkCssBoxes *boxes,
     }
   else if (has_bg_color)
     {
-      gtk_theming_background_snapshot_color (boxes, snapshot, bg_color, background_image);
+      gtk_theming_background_snapshot_color (boxes, snapshot, bg_color, number_of_layers);
     }
 
   if (has_shadow)